#include <iostream>
using namespace std;

typedef struct intNode
{
    int data;
    intNode *next;
} intNode;

typedef struct int_sigleLlink
{
    intNode *head;
    int length;
} IST;

bool insertNode(IST *L, int index, int data)
{
    intNode *newNode = new intNode();
    newNode->data = data;
    if (L->length == 0)
    {
        L->head = newNode;
        L->length++;
        return true;
    }
    index = index > L->length ? L->length : index;
    intNode *curNode = L->head;
    for (int i = 0; i < L->length; i++)
    {
        if (index == 0) // 插头
        {
            L->head = newNode;
            newNode->next = curNode;
            L->length++;
            break;
        }
        if (i + 1 == index) // 非头
        {
            newNode->next = curNode->next;
            curNode->next = newNode;
            L->length++;
            break;
        }
        curNode = curNode->next;
    }
    return true;
}

bool head_insert(IST *L, int num)
{
    return insertNode(L, 0, num);
}

bool end_insert(IST *L, int num)
{
    return insertNode(L, L->length, num);
}

int findx(IST *L, int num){
    intNode *curNode = L->head;
    for (int i = 0; i < L->length; i++)
    {
        if (curNode->data == num) // 非头
        {
            return i;
        }
        curNode = curNode->next;
    }
    return -1;
}

bool deltNode(IST *L, int index)
{
    if (L->length < 1 || index + 1 > L->length)
        return false;
    intNode *curNode = L->head;

    for (int i = 0; i < L->length; i++)
    {
        if (index == 0) // 插头
        {
            L->head = curNode->next;
            L->length--;
            break;
        }
        if (i + 1 == index) // 非头
        {
            curNode->next = curNode->next->next;
            L->length--;
            break;
        }
        curNode = curNode->next;
    }
    return true;
}
IST *init()
{
    IST *L = new IST();
    // intNode* N1 = new intNode();
    // N1->data = 56;
    // L->head = N1;
    // L->length = 1;

    insertNode(L, 6, 1);
    insertNode(L, 6, 3);
    return L;
}

int main(int argc, char const *argv[])
{
    IST *list = init();
    // printf("%d\n",list.length);
    insertNode(list, 6, 2);
    printf("%d\n", list->length);
    deltNode(list, 0);
    printf("%d\n", list->length);
    insertNode(list, 0, 12);
    return 0;
}
